﻿
var id = "131";
var device = "双尼总部展示厅";
var startTime = "2019-11-03";
var startTimes = "11-03 17:00";
var ywh_stand = "5";

/*
*日期选择
*/
function selecttime(fsle) {
    if (fsle == 'current') {
        startTime = $("#countTimestart").val();
        if (startTime != "") {
            WdatePicker({ dateFmt: 'yyyy-MM-dd' })
        }
    }
    $.ajax({
        type: 'post',
        url: "/wap/index/historys.html",
        data: { id: id, startTime: startTime, state: fsle },
        cache: false,
        dtaType: 'json',
        success: function (e) {
            var log = e['log'];
            startTime = e.date;
            $("#countTimestart").val(startTime);
            if (log.length == 0) {
                layer.open({
                    content: '暂无数据',
                    skin: 'msg',
                    time: 1
                })
                return false;
            }
            var html = "";
            var div = "</div><div class='list-c-t'>";
            var state = '良好';
            for (var i = 0; i < log.length; i++) {
                if (log[i].ywh > ywh_stand) {
                    state = '超标';
                } else {
                    state = '良好';
                }
                html += "<div class='list-c'><div class='list-c-t'>" +
                    log[i].date + div + log[i].ywh + div + log[i].pm + div +
                    log[i].nmhc + div + state + "</div><div class='clear'></div></div>";
            }
            $(".list").html(html);
        }
    })
}
/*小时筛选*/
function selecttimes(fsle) {
    if (fsle == 'current') {
        startTimes = $("#countTimestarts").val();
        if (startTimes != "") {
            WdatePicker({ dateFmt: 'MM-dd HH:00' })
        }
    }
    $.ajax({
        type: 'post',
        url: "/wap/index/historyh.html",
        data: { id: id, startTimes: startTimes, state: fsle },
        cache: false,
        dtaType: 'json',
        success: function (e) {
            var log = e['log'];
            startTimes = e.date;
            $("#countTimestarts").val(startTimes);
            if (log.length == 0) {
                layer.open({
                    content: '暂无数据',
                    skin: 'msg',
                    time: 1
                })
                return false;
            }
            var html = "";
            var state = "";
            var div = "</div><div class='list-c-t'>";
            for (var i = 0; i < log.length; i++) {
                if (log[i].ywh > ywh_stand) {
                    state = '超标';
                } else {
                    state = '良好';
                }
                html += "<div class='list-c'><div class='list-c-t'>" +
                    log[i].date + div + log[i].ywh + div + log[i].pm + div +
                    log[i].nmhc + div + state + "</div><div class='clear'></div></div>";
            }
            $(".lists").html(html);
        }
    })
}

/*
*三级联动年月日
*/
$("#date").selectDate()

/*
导出数据报表
*/
$('#excel').click(function () {
    var ymtype = $("input[name='ymtype']:checked").val();
    var year = $('#year option:selected').val();
    var month = $('#month option:selected').val();
    if (ymtype == undefined || year == '') {
        layer.open({
            content: '请选择需要导出类型或时间',
            skin: 'msg',
            time: 1
        })
        return false;
    }
    if (ymtype == 'month' && month == '') {
        layer.open({
            content: '请选择月份',
            skin: 'msg',
            time: 1
        })
        return false;
    }
    var url = "/wap/index/excel.html" + "?year=" + year + "&month=" + month + "&id=" + id;
    var isurl = window.location.href = url;
    setTimeout(function () {
        if (isurl) {
            window.location.href = 'http://www.teirea.cn/static/' + id + '.xlsx';
        }
    }, 1000)
})
$("input[name='ymtype']").click(function () {
    if ($(this).val() == "year") { $("#month").hide(); } else { $("#month").show(); }
})

/*
*返回
*/
$('.submits').click(function () {
    history.go('-1');
});